/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.google.cse.emea.universaltransformer;

import java.util.logging.Logger;
import javax.swing.JLabel;
import javax.swing.JTextArea;

/**
 *
 * @author jtrapp
 */
public class TransformLogger {

    private static Logger LOGGER = Logger.getLogger("com.google.cse.transformer");
    private static JTextArea logOutputTextArea;
    private static JLabel statusLabel;
    private static String lastMessage;

    public static void setOutputTextArea(JTextArea outputArea, JLabel label) {
        logOutputTextArea = outputArea;
        statusLabel= label;
    }

    /** Reflect the current status in the status line.
     * todo place status line.
     */
    public static void status(String message) {
        if ((!message.equals(lastMessage))&&(logOutputTextArea != null)) {
            logOutputTextArea.append(message);
            logOutputTextArea.append("\n");
        }
        lastMessage=message;
        statusLabel.setText(message);
    }


    /** Log a message in the output textarea and the log file.
     * @param level severity
     * @param message What's the problem
     */
    public static void log(java.util.logging.Level level, String message) {
        log(level, message, null);
    }

    /** Log a message in the output textarea and the log file.
     * @param level severity
     * @param message What's the problem
     */
    public static void log(java.util.logging.Level level, String message, Throwable thrown) {
        LOGGER.log(level, message, thrown);
        logOutputTextArea.append(level.toString());
        logOutputTextArea.append(":");
        logOutputTextArea.append(message);
        logOutputTextArea.append("\n");
    }
}
